import type { AddCartParams, CartItem } from '@/types/cart'
import { http } from '@/utils/http'

// 添加购物车
export const postMemberCart = (data: AddCartParams) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data,
  })
}

// 获取购物车列表
export const getMemberCart = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET',
  })
}

// 清空/删除购物车
export const deleteMemberCart = (ids: string[]) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data: {
      ids,
    },
  })
}

// 修改购物车单品状态-单选 数量
export const putMemberCart = (skuId: string, data: { selected?: boolean; count?: number }) => {
  return http({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data,
  })
}

// 购物车商品是否全选
export const putMemberCartSelected = (selected: boolean) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data: {
      selected,
    },
  })
}
